package controllers.residences;

import com.google.appengine.api.NamespaceManager;

import models.Residence;
import play.Logger;
import play.i18n.Messages;
import play.mvc.Before;
import controllers.Secure;

public class SecureResidence extends Secure {
	@Before
	public static void checkResidence() {
		Logger.debug("---------------- checkResidence() ------------------------");
		String name = params.get("residenceName");
		if(name == null || ("").equals(name)) notFound();
		Residence residence = Residence.findByName(name);
		if(residence == null) notFound();
		Logger.debug("---------------- Namespace: %s ------------------------", name);
		flash.put("residenceName", name);
		NamespaceManager.set(String.valueOf(residence.id));
		renderArgs.put("residence", residence);
	}
	
}
